//! event_publisher.rs 单元测试
//! 
//! 测试事件发布器的观察者模式实现

use redis_rs2::server::event_publisher::*;
use redis_rs2::server::enhanced_traits::*;
use tokio_test;

#[cfg(test)]
mod event_publisher_tests {
    use super::*;
    
    #[tokio::test]
    async fn test_default_event_publisher_creation() {
        let publisher = DefaultEventPublisher::new(true);
        let stats = publisher.get_stats().await;
        
        assert_eq!(stats.total_events, 0);
        assert_eq!(stats.listeners_count, 0);
    }
    
    #[tokio::test]
    async fn test_event_type_filter() {
        let filter = EventTypeFilter::errors_only();
        
        let error_event = ServerEvent::Error {
            message: "Test error".to_string(),
            recoverable: true,
        };
        let start_event = ServerEvent::Starting {
            mode: redis_rs2::storage::RedisServerMode::Standalone,
        };
        
        assert!(filter.should_process(&error_event));
        assert!(!filter.should_process(&start_event));
    }
    
    #[tokio::test]
    async fn test_server_mode_filter() {
        let filter = ServerModeFilter::cluster_only();
        
        let cluster_event = ServerEvent::Started {
            mode: redis_rs2::storage::RedisServerMode::Cluster,
            bind_addr: "127.0.0.1:7001".to_string(),
        };
        let standalone_event = ServerEvent::Started {
            mode: redis_rs2::storage::RedisServerMode::Standalone,
            bind_addr: "127.0.0.1:6379".to_string(),
        };
        
        assert!(filter.should_process(&cluster_event));
        assert!(!filter.should_process(&standalone_event));
    }
    
    #[tokio::test]
    async fn test_logging_event_listener() {
        let mut listener = LoggingEventListener::info();
        
        assert_eq!(listener.listener_name(), "LoggingEventListener");
        
        let event = ServerEvent::Starting {
            mode: redis_rs2::storage::RedisServerMode::Standalone,
        };
        
        let result = listener.on_event(event).await;
        assert!(result.is_ok());
    }
}